package com.lin.remote;

import com.lzl.constant.AmapConfigConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * //TODO
 *
 * @author zhaolinlin
 * @description //TODO
 * @createTime 2022/8/23 10:12
 */
@Service
@Slf4j
public class MapDistrictClient {

    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    RestTemplate restTemplate;
//https://restapi.amap.com/v3/config/district?keywords=%E5%B9%BF%E4%B8%9C&subdistrict=4&key=95e0f7be0775ce6a8d1dc1559cf3aa22
    public String district(String keywords){
        log.info("拼接地点区域路径");
        StringBuilder sb = new StringBuilder();
        sb.append(AmapConfigConstants.DISTRICT_URL);
        sb.append("?");
        sb.append("keywords=" + keywords);
        sb.append("&");
        sb.append("subdistrict=3");
        sb.append("&");
        sb.append("key=" + amapKey );
        log.info("区域链接："+ sb.toString());
        ResponseEntity<String>  districtMap = restTemplate.getForEntity(sb.toString(), String.class);
        log.info("获取区域地区信息：" + districtMap.getBody() );
       return districtMap.getBody();

    }
}
